﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;


public partial class Welcome : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        SqlConnection conn = new SqlConnection();
        conn.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionStringProManage"].ConnectionString;
        try
        {
            conn.Open();

            //获取当前的设备数
            int ProNum = 0;
            string SqlProNum = "select pro_num from Products where flag=1";
            SqlCommand cmdSqlProNum = new SqlCommand();
            cmdSqlProNum.Connection = conn;
            cmdSqlProNum.CommandType = CommandType.Text;
            cmdSqlProNum.CommandText = SqlProNum;
            using (SqlDataReader reader = cmdSqlProNum.ExecuteReader())
            {
                while (reader.Read())
                {
                    ++ProNum;
                }
            }
            
            Dev_Num.Text = ProNum.ToString();

            //获取当前设备工程师数
            int DevNum = 0;
            string SqlDevNum = "select uername from Users where flag=1 and usertype=0";
            SqlCommand cmdSqlDevNum = new SqlCommand();
            cmdSqlDevNum.Connection = conn;
            cmdSqlDevNum.CommandType = CommandType.Text;
            cmdSqlDevNum.CommandText = SqlDevNum;
            using (SqlDataReader reader = cmdSqlDevNum.ExecuteReader())
            {
                while (reader.Read())
                {
                    ++DevNum;
                }
            }
            Eng_Num.Text = DevNum.ToString();


            //获取当前正常使用设备数
            int InUseProNum = 0;
            string SqlInUseProNum = "select pro_num from products where flag=1 and condition=N'正常'";
            SqlCommand cmdSqlInUseProNum = new SqlCommand();
            cmdSqlInUseProNum.Connection = conn;
            cmdSqlInUseProNum.CommandType = CommandType.Text;
            cmdSqlInUseProNum.CommandText = SqlInUseProNum;
            using (SqlDataReader reader = cmdSqlInUseProNum.ExecuteReader())
            {
                while (reader.Read())
                {
                    ++InUseProNum;
                }
            }
            OnUse_Num.Text = InUseProNum.ToString();


            float rate = (float)InUseProNum / ProNum;
            float rate2 = (float)Math.Round(rate, 4);
            float rate3 = rate2 * 100;
            //double rate = Math.Round((double)(InUseProNum / ProNum),2);
            InUseDevRate.Text = rate3.ToString()+"%";


            //获取当前待处理预约数
            int BookingToBeNum = 0;
            string SqlBookingToBeNum = "select booking.book_id from booking inner join products on booking.pro_num=products.pro_num where booking.condition=N'已提交' and booking.flag=1 and products.condition=N'正常'";
            SqlCommand SqlCmdBookingToBeNum = new SqlCommand();
            SqlCmdBookingToBeNum.Connection = conn;
            SqlCmdBookingToBeNum.CommandType = CommandType.Text;
            SqlCmdBookingToBeNum.CommandText = SqlBookingToBeNum;
            using (SqlDataReader reader=SqlCmdBookingToBeNum.ExecuteReader())
            {
                while (reader.Read())
                {
                    ++BookingToBeNum;
                }
            }
            BookingToBe.Text = BookingToBeNum.ToString();

            //获取当前待处理的设备数
            int RepairToBeNum = 0;
            string SqlRepairToBeNum = "select rep_id from repair where condition=N'已报修' and flag=1";
            SqlCommand SqlCmdRepairToBeNum = new SqlCommand();
            SqlCmdRepairToBeNum.Connection = conn;
            SqlCmdRepairToBeNum.CommandType = CommandType.Text;
            SqlCmdRepairToBeNum.CommandText = SqlRepairToBeNum;
            using (SqlDataReader reader = SqlCmdRepairToBeNum.ExecuteReader())
            {
                while (reader.Read())
                {
                    ++RepairToBeNum;
                }
            }
            RepairingToBe.Text = RepairToBeNum.ToString();

        }
        finally
        {

        }
    }
}